
<template>
  <header class="header-container">
    <!-- Logo区域 -->
    <div class="logo-area">
      <img :src="logoUrl" alt="" class="logo-img">
      <h1  class="logo-title">{{ title }}</h1>
    </div>

    <!-- 导航菜单 -->
    <nav class="nav-menu">
      <ul class="menu-list">
        <li 
          v-for="(item, index) in menuItems" 
          :key="index"
          @click="handleMenuClick(item)"
        >
          <router-link v-if="item.ishttp" :to="item.url">
            {{ item.name }}
          </router-link>
          <a v-else href="javascript:;">
            {{ item.name }}
          </a>
        </li>
      </ul>
    </nav>

    <!-- 用户信息区域 -->
    <div class="user-area">
      <div class="user-info" v-if="user">
        <img src="https://picsum.photos/50/50" :alt="user.name" class="user-avatar">
        <span class="user-name">{{ user.name }}</span>
      </div>
      <div class="action-buttons">
        <button 
          v-for="(btn, idx) in actionButtons" 
          :key="idx"
          :class="btn.class"
          @click="handleButtonClick(btn)"
        >
          <i v-if="btn.icon" :class="btn.icon"></i>
          {{ btn.text }}
        </button>
      </div>
    </div>
  </header>
</template>

<script>
export default {
  name: 'HeaderNav',
  props: {
    // Logo配置
    logoUrl: {
      type: String,
      default: 'https://picsum.photos/50/50'
    },
    title: {
      type: String,
      default: '网站标题'
    },
    
    // 导航菜单配置
    menuItems: {
      type: Array,
      default: () => []
    },
    
    // 用户信息
    user: {
      type: Object,
      default: () => ({
        name: '用户名',
        avatar: 'https://picsum.photos/50/50'
      })
    },
    
    // 操作按钮
    actionButtons: {
      type: Array,
      default: () => [
        { text: '登录', class: 'login-btn', icon: 'el-icon-user', event: 'login' },
        { text: '注册', class: 'register-btn', icon: 'el-icon-edit', event: 'register' }
      ]
    }
  },
  methods: {
    handleMenuClick(item) {
      // 更新菜单激活状态
    //   this.menuItems.forEach(menu => {
    //     menu.active = menu.text === item.text;
    //   });
      
      // 触发自定义事件
      this.$emit('menu-click', item);
    },
    
    handleButtonClick(btn) {
      // 触发按钮对应事件
      this.$emit(btn.event || 'button-click', btn);
    }
  }
}
</script>

<style scoped>
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 60px;
  background-color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.logo-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}

.logo-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.nav-menu {
  flex: 1;
  margin: 0 20px;
}

.menu-list {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-list li {
  margin: 0 15px;
  position: relative;
}

.menu-list li a {
  text-decoration: none;
  color: #666;
  font-size: 16px;
  display: flex;
  align-items: center;
  padding: 5px 0;
  transition: color 0.3s;
}

.menu-list li a i {
  margin-right: 5px;
}

/* .menu-list li.active a {
  color: #409eff;
  font-weight: bold;
} */

.menu-list li a:hover {
  color: #409eff;
}

.user-area {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  margin-right: 15px;
  cursor: pointer;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 8px;
}

.user-name {
  font-size: 14px;
  color: #333;
}

.action-buttons button {
  padding: 6px 12px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  margin-left: 10px;
  font-size: 14px;
  transition: all 0.3s;
}

.login-btn {
  background-color: #f5f5f5;
  color: #666;
}

.register-btn {
  background-color: #409eff;
  color: #fff;
}

.action-buttons button:hover {
  opacity: 0.8;
}
</style>
